const _ = require("underscore")
const defaultstate = {
    value:0,
    list:[]
}
export const defaultstate2 = {
    list:[]
}
const reducer =(state=defaultstate,action) =>{
    if (action.type ==="change_input"){
        
        let newState = JSON.parse(JSON.stringify(state))
        newState.value = action.value
        return newState
    }

    if (action.type ==="add_item"){
        let newState = JSON.parse(JSON.stringify(state))
        newState.list.push(newState.value)
        newState.value=newState.value//必须重新赋值
        return newState
    }
    return state
}

export const reducer2 =(state,action)=>{
    if (action.type==="compute_item"){
        let newstate = Object.assign({},state)
        newstate.list = _.filter(action.list,
        (item)=>item%2===0)
        console.log(newstate)
        return newstate
    }
    return state
}
export default reducer